package gtug.duesseldorf.server.restlet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;

/**
 * 
 * @author Georg Sendt
 * 
 * 
 */
public class GoogleWaveServerResource extends Resource {

	private final List<String> m_waves = new ArrayList<String>();

	public GoogleWaveServerResource(Context context, Request request,
			Response response) {
		super(context, request, response);

		getVariants().add(new Variant(MediaType.TEXT_PLAIN));

		for (int i = 0; i < 10; i++) {
			m_waves.add(new String(i + "123"));
		}
	}

	/**
	 * Returns a listing of all registered items.
	 */
	@Override
	public Representation represent(Variant variant) throws ResourceException {

		// Generate the right representation according to its media type.
		if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) {
			// if(true)
			// return new StringRepresentation("333");

			Map<String, List<String>> map = new HashMap<String, List<String>>();
			map.put("waves", m_waves);

			JsonRepresentation representation = new JsonRepresentation(map);

			return representation;
		}

		return null;
	}

}
